/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.interactions.traffic;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.mosaic.lib.geo.GeoSector;
import org.eclipse.mosaic.rti.api.Interaction;

import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

/**
 * This extension of {@link Interaction} is sent when a unit wants to subscribe for data of a mec sector
 * area detector
 */
public class MecDetectorSubscription extends Interaction {

    private static final long serialVersionUID = 1L;

    /**
     * String identifying the type of this interaction
     */
    public final static String TYPE_ID = createTypeIdentifier(MecDetectorSubscription.class);

    private final String mecId;

    private final GeoSector area;

    private final boolean enableShow;

    public MecDetectorSubscription(long time, String mecId, GeoSector area, boolean enableShow) {
        super(time);
        this.mecId = mecId;
        this.area = area;
        this.enableShow = enableShow;
    }

    public String getMecId() {
        return mecId;
    }

    public GeoSector getArea() {
        return area;
    }

    public boolean getEnableShow() {
        return enableShow;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(21, 37)
                .append(mecId)
                .append(area)
                .append(enableShow)
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }

        MecDetectorSubscription other = (MecDetectorSubscription) obj;
        return new EqualsBuilder()
                .append(this.mecId, other.mecId)
                .append(this.area, other.area)
                .append(this.enableShow, other.enableShow)
                .isEquals();
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this, SHORT_PREFIX_STYLE)
                .appendSuper(super.toString())
                .append("mecId", mecId)
                .append("area", area)
                .append("enableShow", enableShow)
                .toString();
    }
}
